<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><spring:message code="create_fashion_style"/></title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
	<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
	<link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
	<script src="${ctxStatic}/layDate/laydate.js"></script>
	<script type="text/javascript">
	//文件上传
	function addFinderList(flg) {
		// 表单验证
		 $("#inputForm").validate({
			 submitHandler : function() {
			     
				if($("#nameImage").val()!=''){
					var filePathAndName = $("#nameImage").val().split("/");
					// 判断画面来源
					if (flg==1) {
						var len = filePathAndName.length;
				 		var fileName = $("#nameImagePreview").find("a")[0].text;
						if (fileName=='undefined') {
							fileName='';
						}
				 		var fileUrl="";
				 		for (var i =1;i<(len-1);i++) {
				 			fileUrl += "/"+filePathAndName[i];
				 		}
				 		fileUrl = fileUrl+"/";
				 		//获取 iframe 数量 
				     	var frLength = window.parent.frames.length;
				     	//父画面下标 
				     	var parentIndex = frLength-2;
				 		window.parent.frames[parentIndex].setUpload(fileName,fileUrl);
					} else {
                        styleSampleUpLoadFile(filePathAndName);
                    }
			 		closeWin();
				}
			 },
		 });
		 $("#inputForm").submit();
	}
	
	function styleSampleUpLoadFile(filePathAndName) {
		//获取 iframe 数量 
     	var frLength = window.parent.frames.length;
     	//父画面下标 
     	var parentIndex = frLength-2;
        var tbodyTemp = window.parent.frames[parentIndex].document.getElementById("uploadFileData");
		var len = filePathAndName.length;
 		var fileName = $("#nameImagePreview").find("a")[0].text;
		if (fileName=='undefined') {
			fileName='';
		}
		var lenTr = $(tbodyTemp).find("tr").length;
 		var fileNameHidden = "<input type='hidden' name='uploadFileData.uploadDataList[tempIndex].uploadFileName' value='"+fileName+"'/>";
 		var fileUrl="";
 		for (var i =1;i<(len-1);i++) {
 			fileUrl += "/"+filePathAndName[i];
 		}
 		fileUrl = fileUrl+"/";
 		// 获取当前系统时间
 		var newdate = getNowFormatDate();
 		// 创建提交表单所需要的项目
 		var fileUrlHidden = "<input type='hidden' name='uploadFileData.uploadDataList[tempIndex].filePath' value='"+fileUrl+"'/>";
 		var fileRemarkslHidden = "<input type='hidden' class = 'remarks' name='uploadFileData.uploadDataList[tempIndex].fileRemarks'/>";
 		var createUserHidden = "<input type='hidden' name='uploadFileData.uploadDataList[tempIndex].createUser' value='"+$("#createUser").val()+"' />";
 		var createTimeHidden = "<input type='hidden' name='uploadFileData.uploadDataList[tempIndex].createTime' value='"+$("#createDate").val()+"' />";
 		var ftpFileHidden = "<input type ='hidden' name ='uploadFileData.uploadDataList[tempIndex].ftpFile' value = '/bigcargoStyleFile'/>";
		var fileKbnHidden ="<input type ='hidden' name ='uploadFileData.uploadDataList[tempIndex].fileKbn' value = '1'/>";
        var modelFileHidden = "<input type ='hidden' name='uploadFileData.uploadDataList[tempIndex].moduleKbn' value = '2' />";
 		var hiddenData = fileNameHidden+fileUrlHidden+fileRemarkslHidden+createUserHidden+createTimeHidden+ftpFileHidden+fileKbnHidden+modelFileHidden;
 		var tempData = $(tbodyTemp).find("tr").eq(0).clone();
 		var tempDataCells=$(tempData)[0].cells;
 			tempDataCells[1].innerText=fileName;
 			tempDataCells[3].innerText=newdate;
 			tempDataCells[5].innerHTML = hiddenData;
 		$(tempData)[0].className="";
 		tempData.appendTo(tbodyTemp);
 		window.parent.frames[parentIndex].callBackUpload("#uploadFileData");
	}
   </script>
</head>
<body>
<form id="inputForm" method="post">
<!-- 款式表创建时间 -->
<input type ="hidden" id ="createDate" name ="createDate" value="${fns:getDate('yyyy-MM-dd HH:mm')}">
<!-- 制作单耗 -->
<input type ="hidden" id = "createUser" name ="createUser" value="${fns:getUser()}">
<div class="tabBoxSm">
     <div class="tabSm smOrderBox" style="width:500px">
        <div class="items clearfix">
            <div class="col-50 clearfix">
            	<c:choose>
                <c:when test="${pageFlg=='4'}">
                    <!-- 样板文件上传画面 -->
                     <strong style="font-size:15px;"><spring:message code="template_file_page"/></strong>
                </c:when>
                <c:otherwise>
                    <!-- 资料文件上传画面 -->
                   <strong style="font-size:15px;"><spring:message code="material_file_page"/></strong>
                </c:otherwise>
            </c:choose>
               
            </div>
            <div class="col-50 clearfix" >
            <div style="float:right;">
               <!-- 关闭 -->
               <button type="button" class="btn-js" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
               <!-- 添加 -->
               <button type="button" class="btn-js" onclick="addFinderList(${pageFlg})"><spring:message code="company_account_create"/></button>
               <!-- 上传文件 -->
               <button type="button" class="btn-js" onclick="nameImageFinderOpen()"><spring:message code="upload_file"/></button>
               </div>
            </div>
            <br><hr></hr>
        </div>
        <div class="items clearfix" id ="uploadFile">
             <!-- 上传图片 -->
             <input type="hidden" name="fileId" value="" >
             <input style="width:70%" id="nameImage" type="hidden" name="filePath"  value=""  htmlEscape="false" maxlength="255" class="input-xlarge" data-rule-required="true" data-msg-required="<spring:message code="file_selectOpinion"/>" /> 
             <sys:ckfinder input="nameImage" type="files" uploadPath="/bigcargoStyleFile" selectMultiple="false" maxWidth="100" maxHeight="100" readonly="true"/>
		</div>
     </div>
</div>
</form>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		// 下拉选框带搜索功能
		$("#opinionName").select2();
	});
   </script>
</html>
